package com.binvshe.binvshe.app.home;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;

import com.binvshe.binvshe.R;
import com.binvshe.binvshe.account.Account;
import com.binvshe.binvshe.account.AccountManager;
import com.binvshe.binvshe.account.utils.FragmentUtils;
import com.binvshe.binvshe.mine.corporation.CreatCorpActivity;
import com.binvshe.binvshe.mine.corporation.MyClubActivity;
import com.binvshe.binvshe.organization.ClubSearchResultActivity;
import com.binvshe.binvshe.organization.JoinOrgActivity;
import com.binvshe.binvshe.organization.OrganizationFragment;
import com.binvshe.binvshe.organization.SearchClubActivity;
import com.pachong.android.baseuicomponent.fragment.BaseFragment;
import com.pachong.android.frameworkbase.utils.EasyToast;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class OrgOneFragment extends BaseFragment {


    @Bind(R.id.tvCreate)
    TextView mTvCreate;
    @Bind(R.id.btnSearch)
    Button mBtnSearch;

    FragmentManager fm;
    private boolean isInClub;
    private Account mAccount;

    public OrgOneFragment() {
        setRetainInstance(true);  //转屏不需要重新创建
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, rootView);
        FragmentUtils.replaceFragment(getChildFragmentManager(), R.id.frame_org, new OrganizationFragment());
        return rootView;
    }

    @Override
    public View createDataView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_organization_xml, null);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.tvCreate, R.id.btnSearch})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tvCreate:
                mAccount = AccountManager.getCurrentAccount();
                isInClub = mAccount.getInClub();
                //社团
                if (!isInClub || AccountManager.getCurrentAccount().getClub() == null) {
                    JoinOrgActivity.start(getContext());
                } else {
                    MyClubActivity.start(getActivity());
                    EasyToast.showToast(getContext(),"您已经加入社团");
                }


                break;
            case R.id.btnSearch:

                SearchClubActivity.start(getContext());

                break;
        }
    }
}
